package com.api.shopapi.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.entity.OrderGoodsPrice;
import com.api.shopapi.mapper.OrderGoodsPriceMapper;
import com.api.shopapi.service.OrderGoodsPriceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("OrderGoodsPriceServiceImplOne")
public class OrderGoodsPriceServiceImpl implements OrderGoodsPriceService {

    @Autowired
    private OrderGoodsPriceMapper orderGoodsPriceMapper;

    @Override
    public int insert(OrderGoodsPrice orderGoodsPrice) {
        return orderGoodsPriceMapper.insert(orderGoodsPrice);
    }

    @Override
    public int update(OrderGoodsPrice orderGoodsPrice) {
        return orderGoodsPriceMapper.update(orderGoodsPrice);
    }

    @Override
    public int delete(String orderGoodsPriceCode) {
        return orderGoodsPriceMapper.delete(orderGoodsPriceCode);
    }

    @Override
    public OrderGoodsPrice getByOrderGoodsPriceCode(String orderGoodsPriceCode) {
        return orderGoodsPriceMapper.getByOrderGoodsPriceCode(orderGoodsPriceCode);
    }

    @Override
    public OrderGoodsPrice getByOrderGoodsCode(String orderGoodsCode) {
        return orderGoodsPriceMapper.getByOrderGoodsCode(orderGoodsCode);
    }

    @Override
    public List<JSONObject> getAllOrderGoodsAttribute(String orderGoodsCode) {
        OrderGoodsPrice orderGoodsPrice = orderGoodsPriceMapper.getByOrderGoodsCode(orderGoodsCode);
        List<JSONObject> jsonObjectList=new ArrayList<>();


        if (orderGoodsPrice.getGoodsColorCode()!=null&&!orderGoodsPrice.getGoodsColorCode().equals("")){
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("attributeName","颜色");
            jsonObject.put("attributeValue",orderGoodsPrice.getGoodsColorName());
            jsonObjectList.add(jsonObject);
        }

        if (orderGoodsPrice.getGoodsSizeCode()!=null&&!orderGoodsPrice.getGoodsSizeCode().equals("")){
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("attributeName","大小");
            jsonObject.put("attributeValue",orderGoodsPrice.getGoodsSizeName());
            jsonObjectList.add(jsonObject);
        }
        return jsonObjectList;
    }

    @Override
    public List<OrderGoodsPrice> getList() {
        return orderGoodsPriceMapper.getList();
    }

    @Override
    public PageInfo<OrderGoodsPrice> getPageList(int pageIndex, int pageSize, String goodsSizeName, String goodsColorName) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OrderGoodsPrice> orderGoodsPriceList = orderGoodsPriceMapper.getPageList(goodsSizeName, goodsColorName);
        PageInfo<OrderGoodsPrice> orderGoodsPricePageInfo=new PageInfo<>(orderGoodsPriceList);
        return orderGoodsPricePageInfo;
    }
}
